package com.sikaryofficial.system.api.factory;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.api.RemoteSystemReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 日志服务降级处理
 *
 * @author qinjinyuan
 */
@Component
public class RemoteSystemReportFallbackFactory implements FallbackFactory<RemoteSystemReportService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteSystemReportFallbackFactory.class);

    @Override
    public RemoteSystemReportService create(Throwable throwable) {
        log.error("自动处理举报服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemReportService() {
            /**
             * 日活-定时任务
             *
             * @param timeType 时间类型:day-天,week-周,month-月,quarter-季度,year-年
             * @return 结果
             */
            @Override
            public R<Boolean> activityByType(String timeType) {
                log.error("日活-定时任务 timeType:" + timeType);
                return R.fail("日活-定时任务:" + throwable.getMessage());
            }

            /**
             * 新增用户-定时任务
             *
             * @param timeType
             * @return
             */
            @Override
            public R<Boolean> registerByType(String timeType) {
                log.error("新增用户-定时任务 timeType:" + timeType);
                return R.fail("新增用户-定时任务 fail:" + throwable.getMessage());
            }
        };
    }
}
